<?php
// 本类由系统自动生成，仅供测试用途
class TagAction extends AdminAction{
	public function _initialize() {
        parent::_initialize();  //RBAC 验证接口初始化
    }
	
	private $root_name="";
	private $site_root='';
	private $file_noexist = 'file_noexist';
    private $dele_statice_success = 'dele_statice_success';
    private $dele_statice_fail = 'dele_statice_fail';
    private $delete_success = 'delete_success';
    private $delete_fail = 'delete_fail';
    private $statice_success = 'statice_success';
    private $statice_fail = 'staice_fail';
    private $pro_no_statice_name = 'pro_no_statice_name';
    private $art_no_statice_name = 'art_no_statice_name';
    private $howto_no_statice_name = 'howto_no_statice_name';
    private $plate_no_statice_name = 'plate_no_statice_name';
    public function __construct(){
    	$this->root_name = 'http://'.$_SERVER['HTTP_HOST'].'/index.php';
    	$this->site_root = 'http://'.$_SERVER['HTTP_HOST'];
    	parent::__construct();

    }
	
	
	public function hotTag()
    {
   		
		if($this->isPost()){
			$data['tag_name']=isset($_POST['tag_name'])?trim($_POST['tag_name']):'';
			$data['tag_url']=isset($_POST['tag_url'])?trim($_POST['tag_url']):'';
			if(!$data['tag_name'] || !$data['tag_url'])
			{
				exit('标签名和链接不能为空');
			}
		$ht = M('HotTag');
		if($ht->where("tag_name='".$data['tag_name']."' and tag_url='".$data['tag_url']."'")->find()){
    			echo "<script>alert('标签名已存在，请填写其他标签名');history.back();</script>";
    			return;
    		}
    		if($ht->add($data)){
    			echo "<script>alert('添加成功');location.href='".__URL__."/hot_tag_manage';</script>";
    		}else{
    			echo "<script>alert('添加失败');history.back();</script>";
    		}

    	}else{
    		$this->display();
    	}
    }
	
	//hotTag管理
    public function hot_tag_manage(){
    	
    	$ht = M('HotTag');
    	$cate=$ht->select();
    	$this->assign('cate',$cate);
    	$this->display();
    }
	
//更改hotTag名称
     public function modify_hot_tag(){
    
     	if($this->isPost()){
     		$id=isset($_POST['id'])?intval($_POST['id']):0;
     		$data['tag_name']=isset($_POST['tag_name'])?trim($_POST['tag_name']):'';
			$data['tag_url']=isset($_POST['tag_url'])?trim($_POST['tag_url']):'';
			if(!$data['tag_name'] || !$data['tag_url'])
			{
				exit('标签名和链接不能为空');
			}
			$ht = M('HotTag');
			if($ht->where("tag_name='".$data['tag_name']."' and tag_url='".$data['tag_url']."'")->find()){
	    		echo "<script>alert('标签名已存在，请填写其他标签名');history.back();</script>";
	    		return;
	    	}
     		if($ht->where("id=$id")->save($data)){
     			echo "<script>alert('修改成功');location.href='".__URL__."/hot_tag_manage';</script>";
     		}else{
     			echo "<script>alert('修改失败');history.back();</script>";
     		}
     	}else{
	     	$ht = M('HotTag');
	     	$id=$_GET['id'];
	     	if(!$id){
	     		return;
	     	}
	     	$data=$ht->where('id='.$id)->find();
	     	$this->assign('ht',$data);
	     	$this->display();
     	}
     }

	 
//删除hotTag
    public function delete_hot_tag(){
    	header("Content-Type:text/html; charset=utf-8");
    	
     	$id=$_GET['id'];
      	if (!$id){
     		return;
     	}
     	$ht = M('HotTag');
     	$ret=$ht->where("id=$id")->delete();
    	if(!$ret){
			echo $this->delete_fail;
			return;
     	}else{
			echo $this->delete_success;
     	}
     }
	
}